//
//  commentTableViewCell.m
//  UESTCPioneer
//
//  Created by Apple on 14-8-26.
//  Copyright (c) 2014年 Sway. All rights reserved.
//

#import "commentTableViewCell.h"
#import"commentView.h"

#define cellBackgroundColor [UIColor colorWithRed:237.0/255.0 green:237.0/255.0 blue:237.0/255.0 alpha:1]
@implementation commentTableViewCell

- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

//@ what the hell? 究竟怎么回事，为什么会多出35
-(void)setFrame:(CGRect)frame{
    frame.origin.y-=35;
    [super setFrame:frame];
}

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self){
        [self setBackgroundColor:cellBackgroundColor];
        [self.contentView setBackgroundColor:cellBackgroundColor];
        self.headImageView=[[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 22, 22)];
        self.userName=[[UILabel alloc]initWithFrame:CGRectMake(44, 10, 100, 22)];
        
        self.commentBody=[[UILabel alloc]initWithFrame:CGRectMake(10, 35, self.frame.size.width - 20, 20)];
        [self.commentBody setNumberOfLines:0];
        [self.commentBody setFont:[UIFont systemFontOfSize:14.0f]];
        [self.contentView addSubview:self.commentBody];
        
        self.commentTime = [[UILabel alloc] initWithFrame:CGRectMake(180, self.commentBody.frame.size.height + 40, 130, 15)];
        self.commentTime.font = [UIFont systemFontOfSize:12.0f];
        [self.commentTime setTextColor:[UIColor grayColor]];
        self.commentTime.textAlignment = NSTextAlignmentRight;
        
        self.commentBack = [[UIButton alloc] initWithFrame:CGRectMake(270, 8, 40, 27)];
        self.commentBack.titleLabel.font = [UIFont systemFontOfSize:12.0f];
        [self.commentBack setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        self.commentBack.titleLabel.textAlignment = NSTextAlignmentRight;
        [self.commentBack addTarget:self action:@selector(commentBackClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.commentBack setTitle:@"回复" forState:UIControlStateNormal];
        [self.commentBack setTitle:@"回复" forState:UIControlStateHighlighted];
        [self.commentBack setTitle:@"回复" forState:UIControlStateSelected];
        
        [self.contentView addSubview:self.commentTime];
        [self.contentView addSubview:self.commentBack];
        
        
        [self.contentView addSubview:self.headImageView];
        [self.contentView addSubview:self.userName];
        
        
//        [self.headImageView setTranslatesAutoresizingMaskIntoConstraints:NO];
//        [self.userName setTranslatesAutoresizingMaskIntoConstraints:NO];
//        [self.commentBody setTranslatesAutoresizingMaskIntoConstraints:NO];
        
        [self.userName setFont:[UIFont systemFontOfSize:13]];
        [self.userName setTextColor:[UIColor colorWithRed:69.0/255.0 green:120.0/255.0 blue:200.0/255.0 alpha:1]];
        
        
        /*
        [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[_headImageView(==22)]-[_userName]-|" options:0 metrics:0 views:NSDictionaryOfVariableBindings(_headImageView,_userName)]];
        
        [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-12-[_headImageView(==22)]" options:0 metrics:0 views:NSDictionaryOfVariableBindings(_headImageView)]];
        
        [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-12-[_userName(==22)]" options:0 metrics:0 views:NSDictionaryOfVariableBindings(_userName)]];
        
        [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[_commentBody]-|" options:0 metrics:Nil views:NSDictionaryOfVariableBindings(_commentBody)]];
        
        [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[_userName]-[_commentBody]-|" options:0 metrics:Nil views:NSDictionaryOfVariableBindings(_commentBody,_userName)]];
        */
    }
    return self;
}

-(void)commentBackClick:(UIButton *)btn{
    NSLog(@"回复按钮被点击了。。。btn.titleLabel.text = %@",btn.titleLabel.text);
    [_commentDelegate commentBackBtnClick:self.userName.text];
}

-(void)setCommentBodyFrame:(CGFloat)height{
    CGRect oldFrame = self.commentBody.frame;
    CGRect newFrame = CGRectMake(oldFrame.origin.x, oldFrame.origin.y, oldFrame.size.width, height);
    self.commentBody.frame = newFrame;
    self.commentTime.frame = CGRectMake(170, newFrame.size.height + 40, 140, 15);
//    CGRect cellFrame = self.frame;
//    if (height > 60.0f) {
//        self.frame = CGRectMake(cellFrame.origin.x,cellFrame.origin.y ,cellFrame.size.width , newFrame.size.height + 600.0f);
//        NSLog(@"self.frame.size.height = %f,newFrame.size.height = %f",self.frame.size.height,newFrame.size.height);
//    }
}
@end


